package cn.nb12.xbox.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Servlet Filter implementation class UrlFilter
 */
@WebFilter("/UrlFilter")
public class UrlFilter implements Filter {
	
	private Logger log=LoggerFactory.getLogger(UrlFilter.class);

    /**
     * Default constructor. 
     */
    public UrlFilter() {
    }

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req=(HttpServletRequest)request;
		long time=System.currentTimeMillis();
		log.info("请求到达服务器"+req.getRequestURL());
		chain.doFilter(request, response);
		log.info("请求结束，耗时："+(System.currentTimeMillis()-time));
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
	}

}
